<?php 
namespace app\superadmin\controller;
use think\Db;
use think\Controller;
class Uservideo extends Base{
	public function index(){
		$videos=Db::name('videos v')->join("videotype a","v.tid=a.tid")->join('users u','v.uploadadmin=u.uid')->where("uploadadmin!='0'")->paginate(10);
		$this->assign('videos',$videos);


		//序号
    $page=request()->param('page');
    $page||($page=1);
    $this->assign('page',$page);
    //视频类型
    $types=Db::name('videotype')->where("tstatus='0'")->select();

    //知识体系
    $knows=Db::name('knowledge')->where("kstatus='0'")->select();
    $this->assign("knows",$knows);

    $this->assign('types',$types);
		return $this->fetch();
	}
	//视频详情页
  public function videodetails($vid){
    $videoDetails=Db::name('videos')->alias('v')->join('videotype t','v.tid=t.tid')->join('knowbok k','v.kbid=k.kbid')->join('knowledge l','k.kid=l.kid')->join('users u','v.uploadadmin=u.uid')->where('vid',$vid)->select();
    //子视频目录
    $videochilds=Db::name('videochild')->where('vid',$vid)->paginate(10);
    $this->assign('videoDetails',$videoDetails);
    $this->assign('videochilds',$videochilds);
    	//序号
    $page=request()->param('page');
    $page||($page=1);
    $this->assign('page',$page);
    return $this->fetch();
  }
  //子视频播放页
  public function videochild($cvid){
    $childs=Db::name('videochild')->where('cvid',$cvid)->select();
    $this->assign('childs',$childs);
    return $this->fetch();
  }

  //通过审核
  public function shield6($vid){
  	$res=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>0]);
  	if ($res) {
  		# code...
  		$this->redirect('index');
  	}else{
  		$this->error('通过审核失败！');
  	}
  }
  //封禁理由1
	public function shield1($vid,$uploadadmin){
		// dump($cid);
		// dump($uid);
		// $user=Db::name('users')->where('uname',$uname)->select();
		$user=DB::name('users')->where('uid',$uploadadmin)->select();
		$video=Db::name('videos')->where('vid',$vid)->select();
		// dump($user[0]["uid"]);
		$date=['adminid'=>1,
				'uid'=>$uploadadmin,
				'itime'=>date('Y-m-d H:i:s'),
				'content'=>'您发布的视频'."<<".$video[0]['videoname'].">>".'包含违法信息'];
				// dump($date);
		$res=Db::name('information')->insert($date);
		$res2=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>1]);
		if ($res2) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('封禁失败！');
		}
	}
	//封禁理由2
	public function shield2($vid,$uploadadmin){
		// dump($cid);
		// dump($uid);
		// $user=Db::name('users')->where('uname',$uname)->select();
		$user=DB::name('users')->where('uid',$uploadadmin)->select();
		$video=Db::name('videos')->where('vid',$vid)->select();
		// dump($user[0]["uid"]);
		$date=['adminid'=>1,
				'uid'=>$uploadadmin,
				'itime'=>date('Y-m-d H:i:s'),
				'content'=>'您发布的视频'."<<".$video[0]['videoname'].">>".'包含诋毁本网站信息'];
				// dump($date);
		$res=Db::name('information')->insert($date);
		$res2=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>1]);
		if ($res2) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('封禁失败！');
		}
	}
	//封禁理由3
	public function shield3($vid,$uploadadmin){
		// dump($cid);
		// dump($uid);
		// $user=Db::name('users')->where('uname',$uname)->select();
		$user=DB::name('users')->where('uid',$uploadadmin)->select();
		$video=Db::name('videos')->where('vid',$vid)->select();
		// dump($user[0]["uid"]);
		$date=['adminid'=>1,
				'uid'=>$uploadadmin,
				'itime'=>date('Y-m-d H:i:s'),
				'content'=>'您发布的视频'."<<".$video[0]['videoname'].">>".'包含辱骂他人信息'];
				// dump($date);
		$res=Db::name('information')->insert($date);
		$res2=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>1]);
		if ($res2) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('封禁失败！');
		}
	}

	//封禁理由4
	public function shield4($vid,$uploadadmin){
		// dump($cid);
		// dump($uid);
		// $user=Db::name('users')->where('uname',$uname)->select();
		$user=DB::name('users')->where('uid',$uploadadmin)->select();
		$video=Db::name('videos')->where('vid',$vid)->select();

		// dump($user[0]["uid"]);
		$date=['adminid'=>1,
				'uid'=>$uploadadmin,
				'itime'=>date('Y-m-d H:i:s'),
				'content'=>'您发布的视频'."<<".$video[0]['videoname'].">>".'不符合本网站宗旨'];
				// dump($date);
		$res=Db::name('information')->insert($date);
		$res2=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>1]);
		if ($res2) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('封禁失败！');
		}
	}

	//解除封禁
	public function shield5($vid,$uploadadmin){
		// dump($cid);
		// dump($uid);
		$res=Db::name('videos')->where('vid',$vid)->update(['vstatus'=>2]);
		$user=Db::name('users')->where('uid',$uploadadmin)->select();
		// $res2=Db::name('information')->where('uid',$user[0]['uid'])->delete();
		$date=['adminid'=>1,
				'uid'=>$uploadadmin,
				'itime'=>date('Y-m-d H:i:s'),
				'content'=>'亲亲，刚才管理员开小差了，给您带来的不便敬请谅解，您上传的视频正在审核中！'];
		$res2=Db::name('information')->insert($date);

		if ($res2) {
			# code...
			$this->redirect('index');
		}else{
			$this->error('解除封禁失败！');
		}
	}
}